<?php	
$act = (isset($_REQUEST['act'])) ? addslashes($_REQUEST['act']) : "";
@$ip=$_REQUEST['id'];

$messages="";
switch($act){
	case "info":
		info();
		$template = "service/info";
		break;
	case "list":
		list_service();
		$template = "service/list";
		break;
	case "add":
		add();
		$template = "service/add";
		break;
	case "delete":
		delete();
		$template = "service/delete";
		break;
	case "update":
		update();
		$template = "service/add";
		break;
	default:
		$template = "service/info";
}

function info(){
	global $array_server;
	$array_server = array(
	"10.0.0.1",
	"10.0.0.2",
	"10.0.0.3"
	);
	
	

}

function add(){
		global $dataset, $messages;
		if(isset($_POST['name']))
		{
			$name = $_POST['name'];
			$date = $_POST['date'];
			$version = $_POST['version'];			
			$inserts = array('name' => $name,'date' => $date, 'version' => $version); 
//ham insert trong sql.php
			if($dataset->insert('ql_service', $inserts))
			{
			
				$messages = '	<div class="alert_success">
								<p>
								<img src="images/icon_accept.png" alt="success" class="mid_align"/>
								Success add service.
								</p>
								</div> ';
			}
			else
			{
			
				$messages = '	<div class="alert_error">
							<p>
								<img src="images/icon_error.png" alt="delete" class="mid_align"/>
								Error Notification.
							</p>
						</div>';
			}
			
		}
}

function delete(){
global $dataset, $messages, $myItem ;
$id=$_REQUEST['id'];
if(isset($_GET['id']))
		{
if($dataset->delete('ql_service','id',$id))
			{
			
				$messages = '	<div class="alert_success">
								<p>
								<img src="images/icon_accept.png" alt="success" class="mid_align"/>
								Success delete service.
								</p>
								</div> ';
			}
			else
			{
			
				$messages = '	<div class="alert_error">
							<p>
								<img src="images/icon_error.png" alt="delete" class="mid_align"/>
								Error Notification.
							</p>
						</div>';
			}
			}
			
			else
		{
			if(isset($_POST['id']) && count($_POST['id'])!=0)
			{
				$id = $_POST['id'];
				
				foreach($id as $item)
					$dataset->delete('ql_group','id',$item);
					
				transfer("Delete Item ID ".implode(',',$id), "index.php?com=group&act=list");
			}
			
		}
			
		}

function update(){
global $dataset, $messages, $myItem ;
		
		$id=$_REQUEST['id'];
		//echo $id;
		//die("dung");
		if(isset($_POST['name']))
		{
			$name = $_POST['name'];
			$date = $_POST['date']; 
			$update = array('name' => $name,'date' => $date,'id'=> $id); 

			if($dataset->update('ql_service','id',$id, $update))
			{
			
				$messages = '	<div class="alert_success">
								<p>
								<img src="images/icon_accept.png" alt="success" class="mid_align"/>
								Success add group server.
								</p>
								</div> ';
			}
			else
			{
			
				$messages = '	<div class="alert_error">
							<p>
								<img src="images/icon_error.png" alt="delete" class="mid_align"/>
								Error Notification.
							</p>
						</div>';
			}
			
		}
		
		$group_name = $dataset->get_records_by_group('ql_group');
}


function list_service(){
		global $dataset,$myItems;
		$myItems = $dataset->get_records_by_group('ql_service');
		echo $myItems;
		
}

	
?>